function [DLValues,LstResponses]=ITD(lag)
format bank
%==========================================================================
nReversals=12;
nToInc=8;
% fc=500;
% mf=16;
t_l=lag/(10^6);
% stepsize=0.05;

% nReversals = 8;
% nToInc = 6;  

fReversals = 0;
ConCResp = 0;
LstResponses = [];
RevPoints = [];
DLValues = [];
%==========================================================================

while fReversals < nReversals
    
    [cResp, t_l] =signal_speech(t_l);
%     [cResp, t_l] = signal(fc,t_l);
    
    if cResp == 1 && ConCResp < 1
        ConCResp = ConCResp + 1;
    elseif cResp == 1 && ConCResp == 1
        ConCResp = 0;
        t_l = t_l/1.25;
    elseif cResp == 0
        ConCResp = 0;
        t_l = t_l*1.25;
    end
    
    LstResponses = [LstResponses cResp];
    DLValues = [DLValues t_l];
    
    if length(LstResponses)>1 && LstResponses(end)~= LstResponses(end-1);
        MidPoint = (DLValues(numel(LstResponses))+ DLValues(numel(LstResponses)-1))/2;
        RevPoints = [RevPoints MidPoint];
        fReversals = fReversals + 1;
    end
    %     pause;
end
RevPoints(1:(nReversals - nToInc)) = [];
threshold = (prod(RevPoints)).^(1/length(RevPoints));
ITD_ms=threshold*10^6
savefile = '****.mat';
save(savefile,'DLValues','LstResponses','ITD_ms');
msgbox('Trial completed. Please close the user interface ''resp_gui'' by clicking ''X'' on the top right corner  ','Trial End','modal');